/**
 *
 */
package org.doit.android.bobple.history;

import java.util.List;

import org.doit.android.bobple.R;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;

/**
 * @author Choi HongKi
 *
 */
public class HistoryAdapter extends ArrayAdapter<History> {
	private List<History> historyList;
	private Context context;

	private static final int LAYOUT_RESOURCE_ID = R.layout.history_item;

	public HistoryAdapter(Context context, List<History> historyList) {
		super(context, LAYOUT_RESOURCE_ID, historyList);

		this.historyList = historyList;
		this.context = context;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		if (convertView == null) {
			LayoutInflater inflater = (LayoutInflater)this.context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);

			convertView = inflater.inflate(LAYOUT_RESOURCE_ID, null);
		}

		History history = historyList.get(position);

		/* set ymd */
		{
			TextView tvYmd = (TextView)convertView.findViewById(R.id.history_item_ymd);
			tvYmd.setText(history.getYmd());
		}

		/* set restaurant name */
		{
			TextView tvRestaurant = (TextView)convertView.findViewById(R.id.history_item_restaurant);
			tvRestaurant.setText(history.getRestaurantName());
		}

		/* set score */
		{
			TextView tvScore = (TextView)convertView.findViewById(R.id.history_item_score);

			// 이미지로 갈거임.. -_-/
			String scoreText = null;
			switch (history.getScore()) {
				case -1:
					scoreText = "-ㅁ-";
					break;
				case 1:
					scoreText = "^-^";
					break;
			}

			if (scoreText != null) {
				tvScore.setText(scoreText);
			}
		}

		return convertView;
	}
}